//
//  CAnAlgSleep.m
//  sr01sdkProject
//
//  Created by  on 2024/9/4.
//

#import "CAnAlgSleep.h"

@implementation CAnAlgSleep

-(NSNumber *)dataTimeStamp
{
    return @(self.timeStamp);
}

- (instancetype)initWithData:(NSData *)data
{
    self = [super init];
    if (self) {
        
        if (data.length < 20) {
            return self;
        }
        
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        _cmdByte = dataBytes[1];
        // 四字节时间戳
        uint32_t timeStamp = *((uint32_t *)(dataBytes + 2));
        _timeStamp = timeStamp;
        
        uint32_t uuid = (dataBytes[8]<< 16) +(dataBytes[7]<< 8) +dataBytes[6];
        _dataUuid = @(uuid);
        _state = dataBytes[9];
        _sleepDataTimeStamp = *((uint32_t *)(dataBytes + 10));
        _onBedDuration = *((uint16_t *)(dataBytes + 14));
        _wakeIndex = dataBytes[16];
        
    }
    return self;
}
@end
